/*
 * 23/10/2011 - 19:04
 */
package org.nettyflux.tcp;

import java.net.InetAddress;
import org.nettyflux.communicator.RemoteHost;

/**
 * @author Victor Williams Stafusa da Silva
 */
public final class TCPHost implements RemoteHost {

    private final InetAddress address;
    private final int port;

    public TCPHost(InetAddress address, int port) {
        if (address == null || port < 0 || port > 0xFFFF) {
            throw new IllegalArgumentException();
        }
        this.address = address;
        this.port = port;
    }

    public InetAddress getAddress() {
        return address;
    }

    public int getPort() {
        return port;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (obj == null || this.getClass() != obj.getClass()) return false;
        TCPHost other = (TCPHost) obj;
        return this.address.equals(other.address) && this.port == other.port;
    }

    @Override
    public int hashCode() {
        return this.address.hashCode() + this.port;
    }

    @Override
    public String toString() {
        return "Address: " + this.address + ", TCP remote port: " + this.port;
    }
}
